package net.zjitc.android2019.ch2activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


import net.zjitc.android2019.R;

public class ch3Day5Work extends AppCompatActivity {
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ch3_day5_work);
        listView=findViewById(R.id.ch2_market_listview_work);

        final YourAdapter adapter = new YourAdapter();
        listView.setAdapter(adapter);
        AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String s = adapter.names[position];
                Toast.makeText(ch3Day5Work.this,s,Toast.LENGTH_SHORT).show();
            }
        };
       listView.setOnItemClickListener(listener);

    }

    private class YourAdapter extends BaseAdapter {
        int[] img={R.drawable.xunyu,R.drawable.diaochan,R.drawable.sunluban,R.drawable.huangyuey,R.drawable.lusu,R.drawable.luxun};
        String[] names ={"荀彧","貂蝉","孙鲁班","黄月英","鲁肃","陆逊"};
        String[] name2 ={"价格：998","价格：30","价格：36","价格：120","价格：875","价格：321"};
        @Override
        public int getCount() {
            return names.length;
        }

        @Override
        public Object getItem(int position) {
            return names[position];
        }


        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder = new ViewHolder();
            if (convertView==null){
                convertView=View.inflate(ch3Day5Work.this,R.layout.activity_ch2_day5_item,null);
                viewHolder.imageView=convertView.findViewById(R.id.ch2_market_item_image_work);
                viewHolder.textView=convertView.findViewById(R.id.ch2_market_item_tv_work);
                viewHolder.textView1=convertView.findViewById(R.id.ch2_market_item_image_work_2);
                convertView.setTag(viewHolder);
            }else {
                viewHolder= (ViewHolder) convertView.getTag();
            }
            viewHolder.imageView.setImageResource(img[position]);
            viewHolder.textView.setText(names[position]);
            viewHolder.textView1.setText(name2[position]);

            return convertView;
        }

    }
    class ViewHolder{
        ImageView imageView;
        TextView textView;
        TextView textView1;
    }
}
